package com.yayo.mangement.service.impl;

import com.yayo.mangement.executors.ExcelExecutorRegister;
import com.yayo.mangement.iface.XlsxExporter;
import com.yayo.mangement.resp.WorkbookResp;
import com.yayo.mangement.service.XlsxExportService;
import com.yayo.mangement.task.ExportTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class XlsxExportServiceImpl implements XlsxExportService {

    @Autowired
    private ExcelExecutorRegister register;

    @Autowired
    private ExportTask exportTask;

    @Override
    public WorkbookResp exporter(String name, String exportContextJson) {
        XlsxExporter xlsxExporter = register.getXlsxExporter(name);
        List<Object> exportList = xlsxExporter.export(xlsxExporter.getC(exportContextJson));
        try {
            return exportTask.xlsxExportTask(exportList, xlsxExporter.getT().getClass());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
